package com.zp.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.zp.common.core.controller.BaseController;
import com.zp.common.core.entity.R;
import com.zp.common.core.validate.AddGroup;
import com.zp.common.core.validate.EditGroup;
import com.zp.common.log.annotation.Log;
import com.zp.common.log.enums.BusinessType;
import com.zp.common.myBatis.core.page.PageQuery;
import com.zp.common.myBatis.core.page.TableDataInfo;
import com.zp.system.entity.bo.SysOrgGroupVsDeptBo;
import com.zp.system.entity.vo.SysOrgGroupVsDeptVo;
import com.zp.system.service.ISysOrgGroupVsDeptService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 科室分组与科室对照控制器
 * 前端访问路由地址为:/system/groupVsDept
 *
 * @author zhang peng
 * @date 2022-12-18
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/groupVsDept")
public class SysOrgGroupVsDeptController extends BaseController {

    private final ISysOrgGroupVsDeptService iSysOrgGroupVsDeptService;

    /**
     * 查询科室分组与科室对照列表 (分页)
     */
    @SaCheckPermission("system:groupVsDept:list")
    @GetMapping("/selectPage")
    public TableDataInfo<SysOrgGroupVsDeptVo> selectPage (SysOrgGroupVsDeptBo bo, PageQuery pageQuery) {
        return iSysOrgGroupVsDeptService.queryPageList(bo, pageQuery);
    }

    /**
     * 查询科室分组与科室对照列表 (不分页)
     */
    @SaCheckPermission("system:groupVsDept:list")
    @GetMapping("/list")
    public R<List<SysOrgGroupVsDeptVo>> list (SysOrgGroupVsDeptBo bo) {
        List<SysOrgGroupVsDeptVo> list = iSysOrgGroupVsDeptService.queryList(bo);
        return R.ok(list);
    }


    /**
     * 获取科室分组与科室对照详细信息
     *
     * @param deptGroupId 主键
     */
    @SaCheckPermission("system:groupVsDept:query")
    @GetMapping("/{deptGroupId}")
    public R<SysOrgGroupVsDeptVo> getInfo (@NotNull(message = "主键不能为空") @PathVariable String deptGroupId) {
        return R.ok(iSysOrgGroupVsDeptService.queryById(deptGroupId));
    }

    /**
     * 新增科室分组与科室对照
     */
    @SaCheckPermission("system:groupVsDept:add")
    @Log(title = "科室分组与科室对照", businessType = BusinessType.INSERT)
    @PostMapping()
    public R<Void> add (@Validated(AddGroup.class) @RequestBody SysOrgGroupVsDeptBo bo) {
        return toAjax(iSysOrgGroupVsDeptService.insertByBo(bo) ? 1 : 0);
    }

    /**
     * 修改科室分组与科室对照
     */
    @SaCheckPermission("system:groupVsDept:edit")
    @Log(title = "科室分组与科室对照", businessType = BusinessType.UPDATE)
    @PutMapping()
    public R<Void> edit (@Validated(EditGroup.class) @RequestBody SysOrgGroupVsDeptBo bo) {
        return toAjax(iSysOrgGroupVsDeptService.updateByBo(bo) ? 1 : 0);
    }

    /**
     * 删除科室分组与科室对照
     *
     * @param deptGroupIds 主键串
     */
    @SaCheckPermission("system:groupVsDept:remove")
    @Log(title = "科室分组与科室对照", businessType = BusinessType.DELETE)
    @DeleteMapping("/{deptGroupIds}")
    public R<Void> remove (@NotEmpty(message = "主键不能为空") @PathVariable String[] deptGroupIds) {
        return toAjax(iSysOrgGroupVsDeptService.deleteWithValidByIds(Arrays.asList(deptGroupIds), true) ? 1 : 0);
    }
}
